# Build the scheduler binary
FROM golang:1.19 as builder

#RUN apt-get -y update && apt-get -y install upx

WORKDIR /workspace
# Copy the Go Modules manifests
#COPY go.mod go.mod
#COPY go.sum go.sum

# Copy the go source
#COPY main.go main.go
#COPY pkg/ pkg/
COPY . .
# Build
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
ENV GO111MODULE=on
ENV GOPROXY="https://goproxy.cn"

# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
#RUN go mod download && \
#    go build -a -o networktraffic-scheduler main.go && \
#    upx networktraffic-scheduler

#RUN go mod download && \
#    go build -a -o networktraffic-scheduler main.go
RUN --mount=type=cache,mode=0777,id=go-mod,target=/go/pkg/mod  go mod download && \
    go build -a -o networktraffic-scheduler ./cmd/scheduler/main.go
FROM busybox:1.28.4
COPY --from=builder /workspace/networktraffic-scheduler /usr/local/bin/networktraffic-scheduler
